package com.czxy.dao;

import com.czxy.domain.User;
import com.czxy.domain.UserVo;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

public interface UserMapper {

    @Select("select * from user")
    @Results(id = "rel1",value = {
            @Result(property = "a_d_r_ess",column = "address")
    })
    public List<User> findAll();


    @Select("select * from user where birthday >#{startTime} and birthday<#{endTime} and user_name like #{user_name}")
    @ResultMap("rel1")
    public List<User> findUsers(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("user_name") String user_name);



    @Select("select * from user where birthday >#{startTime} and birthday<#{endTime} " +
            "and user_name like #{user.userName} and sex=#{user.sex} ")
    @ResultMap("rel1")
    public List<User> findUsersByUserVo(UserVo userVo);


    @Select("select  *  from user where uid = #{uid}")
    @Results({
            @Result(property = "a_d_r_ess",column = "address"),
            @Result(property = "uid",column = "uid"),
            @Result(property = "orderList",many = @Many(select = "com.czxy.dao.OrderMapper.findOrdersByUserId"),column = "uid")
    })
    public User findUserByUid(@Param("uid") Integer uid);


}
